use crate::backend::Backend;
use crate::ir::IR;

pub struct SunXi{}


impl Backend for SunXi{
    fn gen(&self, ir: &[IR]) -> String {
        let mut out_str = String::new();

        for line in ir {
            match line {
                IR::Transfer { cmd, data } => {
                    let para = data.len();
                    let mut paras = String::new();
                    for p in data {
                        paras = format!("{paras}, 0x{:02X}", p);
                    }
                    out_str = format!("{}sunxi_lcd_dsi_dcs_write_{para}para(sel, 0x{:02X}{paras});\n", out_str, cmd);
                }
                IR::Delay(delay) => {
                    out_str = format!("{}sunxi_lcd_delay_ms({});\n", out_str, delay.as_millis())
                }
            }
        }

        out_str
    }
}

